package zhjb.platform.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BaseAction {
	protected long total;
	protected int page = 0;
	protected int pageSize = 10;
	protected HttpServletRequest request;
	protected HttpServletResponse response;

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void writeString(String message, String contentType, boolean close, boolean flush) {
		System.out.println(message);
		response.setCharacterEncoding("UTF-8");
		response.setContentType(contentType);
		PrintWriter out = null;
		try {
			out = response.getWriter();
			out.write(message);
			if (flush) {
				out.flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (close) {
			if (out != null) {
				out.close();
			}
		}
	}
}
